package com.opengms.HydroModelsIntegration.Dao;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @Author: David.Xiao
 * @Date: 2019/1/3 22:56
 * @Description:
 */
public class DataConverter {

    public void udx2Inp(String udxFileNameFullPath,String inpFileNameFullPath)
    {
        String inpFileName = null;
        if(udxFileNameFullPath.endsWith(".xml"))
        {
            String udx2InpCmd[] = new String[3];
            udx2InpCmd[0] = new File(this.getClass().getResource("/").getPath()+"\\SwmmDataUdxConvert\\SwmmDataUDXConverter.exe").getPath();
            udx2InpCmd[1] = new File(udxFileNameFullPath).toString();
            udx2InpCmd[2] = new File(inpFileNameFullPath).toString();
            inpFileName = udx2InpCmd[2];
            this.invokeExe(udx2InpCmd);
        }
    }

    public void rpt2Udx(String rptFileFullPath,String udxFileFullPath)
    {
//        String rptFolderPath = new File(this.getClass().getResource("/").getPath()+"\\Output").getPath();
//        if (!FileHelper.pathExists(new File(rptFolderPath)))
//        {
//            return null;
//        }
        String udxFileName = null;
        if(rptFileFullPath.endsWith(".rpt"))
        {
            String rpt2UdxCmd[] = new String[3];
            File cmdFile0 = new File(this.getClass().getResource("/").getPath()+"\\SwmmDataUdxConvert\\SwmmDataUDXConverter.exe");
            File cmdFile1 = new File(rptFileFullPath);
            File cmdFile2 = new File(udxFileFullPath);

            rpt2UdxCmd[0] = cmdFile0.getPath();
            rpt2UdxCmd[1] = cmdFile1.getPath();
            rpt2UdxCmd[2] = cmdFile2.getPath();

            udxFileName = rpt2UdxCmd[2];
            this.invokeExe(rpt2UdxCmd);
        }
    }

    public void invokeExe(String[] cmds)
    {
        Runtime runtime = Runtime.getRuntime();
        Process process = null;
        try {
            process = runtime.exec(cmds);
            process.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return;
    }



}
